//
//  ZpStatusOriginalView.m
//  WeiBo_OC
//
//  Created by MacBook Pro on 16/5/30.
//  Copyright © 2016年 MacBook Pro. All rights reserved.
//

#import "ZpStatusOriginalView.h"
#import "ZpPictureCollectionView.h"

#define iconSize 40
@interface ZpStatusOriginalView ()

@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *scourceLabel;
@property (nonatomic, strong) UIImageView *mbrank;
@property (nonatomic, strong) UIImageView *verified;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) ZpPictureCollectionView *picView;
@end
@implementation ZpStatusOriginalView

- (void)setStatusViewModel:(ZpStatusViewModel *)statusViewModel{
    
    _statusViewModel = statusViewModel;
    [self addSubview:self.iconView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.timeLabel];
    [self addSubview:self.scourceLabel];
    [self addSubview:self.mbrank];
    [self addSubview:self.verified];
    [self addSubview:self.contentLabel];
    [self addSubview:self.picView];
    [self setUIContraints];
    [self setUIData];

    self.backgroundColor = [UIColor orangeColor];
}

- (void)setUIData{
    
    if (self.statusViewModel.mbrankImage) {
        self.mbrank.image = self.statusViewModel.mbrankImage;
        self.mbrank.hidden = NO;
    }else{
        self.mbrank.hidden = YES;
    }
    
    if (self.statusViewModel.veritiedImage) {
        _verified.hidden = NO;
    }else{
        _verified.hidden = YES;
    }
    
    [self.iconView sd_setImageWithURL:self.statusViewModel.iconUrl];
    self.nameLabel.text = self.statusViewModel.status.user.name;
    self.timeLabel.text = self.statusViewModel.time;
    self.scourceLabel.text = self.statusViewModel.source;
    self.contentLabel.text = self.statusViewModel.status.text;
    self.picView.pics = self.statusViewModel.status.pic_urls;

}

-(void)setUIContraints{
    [self.iconView makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(margin);
        make.width.equalTo(iconSize);
        make.height.equalTo(iconSize);
    }];
    
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView);
        make.left.equalTo(self.iconView.right).offset(margin);
    }];
    
    [self.mbrank makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView);
        make.left.equalTo(self.nameLabel.right).offset(margin);
    }];
    
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.iconView);
        make.left.equalTo(self.iconView.right).offset(margin);
    }];
    
    [self.scourceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.timeLabel);
        make.left.equalTo(self.timeLabel.right).offset(margin);
    }];
    
    [self.verified makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(self.iconView);
    }];
    
    [self.contentLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.bottom).offset(margin);
        make.left.equalTo(self.iconView);
        make.right.equalTo(self).offset(-margin);
    }];
    
    [self.picView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self.contentLabel.bottom).offset(margin);
        
    }];
    
    [self makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.picView);
    }];
    

}


- (UIImageView *)iconView{
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
        _iconView.layer.cornerRadius = iconSize / self.getScale;
        _iconView.clipsToBounds = YES;
    }
    return _iconView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont systemFontOfSize:10];
    }
    return _nameLabel;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
       _timeLabel = [[UILabel alloc] init];
       _timeLabel.font = [UIFont systemFontOfSize:10];
    }
    return _timeLabel;
}

- (UILabel *)scourceLabel{
    if (!_scourceLabel) {
        _scourceLabel = [[UILabel alloc] init];
        _scourceLabel.font = [UIFont systemFontOfSize:10];
    }
    
    return _scourceLabel;
}

- (UIImageView *)mbrank{
    if (!_mbrank) {
         _mbrank = [[UIImageView alloc] initWithImage:self.statusViewModel.mbrankImage];
    }
       return _mbrank;
}

- (UIImageView *)verified{
    if (!_verified) {
        _verified = [[UIImageView alloc] initWithImage:self.statusViewModel.veritiedImage];
    }
    return _verified;
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.font = [UIFont systemFontOfSize:13];
        _contentLabel.numberOfLines = 0;
        _contentLabel.backgroundColor = [UIColor greenColor];
    }
    
    return _contentLabel;
}

- (ZpPictureCollectionView *)picView{
    if (!_picView) {
        
        _picView = [ZpPictureCollectionView pictureCollectionView];
    }
    return _picView;
}
@end
